package com.global.gbinventory.data.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;

import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.border.LineBorder;
import javax.swing.JButton;

import com.global.gbinventory.main.model.GBTableModel;

public class SupplierListFrame extends JInternalFrame {

	private static final long serialVersionUID = 1179447365862117729L;
	
	private JPanel panelButtons;
	private JTable table;
	private JTextField txtFldKodeSearch;
	private JTextField txtFldNamaSearch;
	private JTextField txtFldAlamatSearch;
	private JTextField txtFldKotaSearch;
	
	private JButton btnOk;
	private JButton btnCancel;
	/**
	 * Create the frame.
	 */
	public SupplierListFrame() {
		//resizeable, closeable, maximizable, iconifiable
		super("Daftar Supplier", false, true, false, true);
		setBounds(100, 100, 881, 573);


		JPanel leftPanel = new JPanel();
		getContentPane().add(leftPanel, BorderLayout.WEST);

		JPanel rightPanel = new JPanel();
		getContentPane().add(rightPanel, BorderLayout.EAST);

		JPanel upPanel = new JPanel();
		getContentPane().add(upPanel, BorderLayout.NORTH);

		JPanel bottomPanel = new JPanel();
		getContentPane().add(bottomPanel, BorderLayout.SOUTH);

		JPanel panel = new JPanel(new BorderLayout());
		getContentPane().add(panel, BorderLayout.CENTER);

		JPanel panelAbove = new JPanel();
		panelAbove.setBorder(new LineBorder(new Color(0, 0, 0)));
		panelAbove.setPreferredSize(new Dimension(10, 100));
		panel.add(panelAbove, BorderLayout.NORTH);
		panelAbove.setLayout(new BorderLayout());

		JPanel panel_1 = new JPanel();
		panelAbove.add(panel_1, BorderLayout.WEST);

		JPanel panel_2 = new JPanel();
		panelAbove.add(panel_2, BorderLayout.EAST);

		JPanel panelSearch = new JPanel();
		panelAbove.add(panelSearch, BorderLayout.CENTER);
		panelSearch.setLayout(null);
		
		JLabel lblKodeSearch = new JLabel("Kode Supplier : ");
		lblKodeSearch.setBounds(77, 18, 132, 16);
		panelSearch.add(lblKodeSearch);
		
		JLabel lblNamaSearch = new JLabel("Nama Supplier : ");
		lblNamaSearch.setBounds(77, 46, 132, 16);
		panelSearch.add(lblNamaSearch);
		
		txtFldKodeSearch = new JTextField();
		txtFldKodeSearch.setBounds(207, 12, 176, 28);
		panelSearch.add(txtFldKodeSearch);
		txtFldKodeSearch.setColumns(10);
		
		txtFldNamaSearch = new JTextField();
		txtFldNamaSearch.setBounds(207, 40, 176, 28);
		panelSearch.add(txtFldNamaSearch);
		txtFldNamaSearch.setColumns(10);
		
		JLabel lblAlamatSearch = new JLabel("Alamat Supplier : ");
		lblAlamatSearch.setBounds(421, 18, 132, 16);
		panelSearch.add(lblAlamatSearch);
		
		JLabel lblKotaSearch = new JLabel("Nama Agen : ");
		lblKotaSearch.setBounds(421, 46, 132, 16);
		panelSearch.add(lblKotaSearch);
		
		txtFldAlamatSearch = new JTextField();
		txtFldAlamatSearch.setColumns(10);
		txtFldAlamatSearch.setBounds(565, 12, 176, 28);
		panelSearch.add(txtFldAlamatSearch);
		
		txtFldKotaSearch = new JTextField();
		txtFldKotaSearch.setColumns(10);
		txtFldKotaSearch.setBounds(565, 40, 176, 28);
		panelSearch.add(txtFldKotaSearch);

		JPanel panel_3 = new JPanel();
		panelAbove.add(panel_3, BorderLayout.NORTH);

		JPanel panel_4 = new JPanel();
		panelAbove.add(panel_4, BorderLayout.SOUTH);

		JPanel panelCenter = new JPanel();
		panel.add(panelCenter, BorderLayout.CENTER);
		panelCenter.setLayout(new BorderLayout());

		JPanel panel_5 = new JPanel();
		panelCenter.add(panel_5, BorderLayout.NORTH);

		JPanel panelTable = new JPanel(new BorderLayout());
		panelCenter.add(panelTable, BorderLayout.CENTER);

		JScrollPane scrollPane = new JScrollPane();
		panelTable.add(scrollPane, BorderLayout.CENTER);

		table = new JTable();
		table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		table.setFillsViewportHeight(true);
		scrollPane.setViewportView(table);

		panelButtons = new JPanel();
		panelButtons.setBorder(new LineBorder(new Color(0, 0, 0)));
		panelButtons.setPreferredSize(new Dimension(10, 40));
		panel.add(panelButtons, BorderLayout.SOUTH);
		panelButtons.setLayout(new FlowLayout());
		
		btnOk = new JButton("Ok");
		panelButtons.add(btnOk);
		
		btnCancel = new JButton("Cancel");
		panelButtons.add(btnCancel);

	}
	
	public void displayFrame(boolean state, boolean viewedOnly){
		if(viewedOnly){
			btnOk.setVisible(false);
			btnCancel.setText("Close");
		}
		setVisible(state);
	}
	
	public void disposeFrame(){
		dispose();
	}
	
	public void setTableModel(GBTableModel tableModel){
		table.setModel(tableModel);
	}
	
	public int getTableSelectedRow(){
		return table.getSelectedRow();
	}
	
	public void addBtnOkListener(ActionListener l){
		btnOk.addActionListener(l);
	}
	
	public void addBtnCancelListener(ActionListener l){		
		btnCancel.addActionListener(l);
	}
}
